package com.logistics.controller;

import com.logistics.common.Result;
import com.logistics.entity.Warehouse;
import com.logistics.service.WarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("/api/warehouse")
public class WarehouseController {
    @Autowired
    private WarehouseService warehouseService;

    @PostMapping
    public Result<Warehouse> create(@RequestBody Warehouse warehouse) {
        return warehouseService.create(warehouse);
    }

    @GetMapping("/{id}")
    public Result<Warehouse> getById(@PathVariable Long id) {
        return warehouseService.getById(id);
    }

    @GetMapping("/list")
    public Result<List<Warehouse>> list() {
        return warehouseService.list();
    }

    @GetMapping("/search")
    public Result<List<Warehouse>> search(@RequestParam(required = false) String name,
                                        @RequestParam(required = false) Integer status) {
        return warehouseService.search(name, status);
    }

    @PutMapping
    public Result<Warehouse> update(@RequestBody Warehouse warehouse) {
        return warehouseService.update(warehouse);
    }

    @DeleteMapping("/{id}")
    public Result<Void> delete(@PathVariable Long id) {
        return warehouseService.delete(id);
    }

    @PutMapping("/{id}/capacity")
    public Result<Void> updateUsedCapacity(@PathVariable Long id, @RequestParam BigDecimal usedCapacity) {
        return warehouseService.updateUsedCapacity(id, usedCapacity);
    }
} 